package echat.future.cn.echat.video.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;

import com.xiao.nicevideoplayer.ChangeClarityDialog;
import com.xiao.nicevideoplayer.NiceVideoPlayerController;

import echat.future.cn.echat.R;

/**
 * Created by Administrator on 2018/8/15.
 */

public class VideoController  extends NiceVideoPlayerController implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, ChangeClarityDialog.OnClarityChangedListener {
    public VideoController(Context context,PlayChangeListener playChangeListener) {
        super(context);
        this.playChangeListener = playChangeListener;
        View v = LayoutInflater.from(context).inflate(R.layout.video_controller_view, this, true);
        v.findViewById(R.id.ll_parent).setOnClickListener(this);
        iv_play = v.findViewById(R.id.iv_play);
        iv_ready = v.findViewById(R.id.iv_ready);

    }

    public View iv_play;
    private ImageView iv_ready;
    private PlayChangeListener playChangeListener;
    public interface PlayChangeListener{
        void playChange();
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_parent:
                //播放与暂停
                if(playChangeListener!=null){
                    playChangeListener.playChange();
                }else{
                    if(mNiceVideoPlayer.isPlaying()){
                        mNiceVideoPlayer.pause();
//                    iv_play.setVisibility(View.VISIBLE);
                    }else{
                        mNiceVideoPlayer.restart();
//                    iv_play.setVisibility(View.GONE);
                    }
                }

                break;

            default:
                break;
        }
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onClarityChanged(int i) {

    }

    @Override
    public void onClarityNotChanged() {

    }

    @Override
    public void setTitle(String s) {

    }

    @Override
    public void setImage(int i) {

    }

    @Override
    public ImageView imageView() {
        return iv_ready;
    }

    @Override
    public void setLenght(long l) {

    }

    @Override
    protected void onPlayStateChanged(int playState) {

        switch(playState) {
            case -1:
//                this.cancelUpdateProgressTimer();
//            this.setTopBottomVisible(false);
//            this.mTop.setVisibility(0);
//            this.mError.setVisibility(0);
            case 0:
            default:
                break;
            case 1:
                iv_ready.setVisibility(VISIBLE);
//                System.out.println("正在准备...");
//            this.mImage.setVisibility(8);
//            this.mLoading.setVisibility(0);
//            this.mLoadText.setText("正在准备...");
//            this.mError.setVisibility(8);
//            this.mCompleted.setVisibility(8);
//            this.mTop.setVisibility(8);
//            this.mBottom.setVisibility(8);
//            this.mCenterStart.setVisibility(8);
//            this.mLength.setVisibility(8);
                break;
            case 2:
//                this.startUpdateProgressTimer();
                break;
            case 3:
                iv_ready.setVisibility(GONE);
                iv_play.setVisibility(View.GONE);
//            this.mLoading.setVisibility(8);
//            this.mRestartPause.setImageResource(drawable.ic_player_pause);
//            this.startDismissTopBottomTimer();
                break;
            case 4:
                //暂停了
                iv_play.setVisibility(View.VISIBLE);
//            this.mLoading.setVisibility(8);
//            this.mRestartPause.setImageResource(drawable.ic_player_start);
//            this.cancelDismissTopBottomTimer();
                break;
            case 5:
                iv_ready.setVisibility(VISIBLE);
//                System.out.println("正在缓冲...");
//            this.mLoading.setVisibility(0);
//            this.mRestartPause.setImageResource(drawable.ic_player_pause);
//            this.mLoadText.setText("正在缓冲...");
//            this.startDismissTopBottomTimer();
                break;
            case 6:
                iv_ready.setVisibility(VISIBLE);
//                System.out.println("正在缓冲...");
//            this.mLoading.setVisibility(0);
//            this.mRestartPause.setImageResource(drawable.ic_player_start);
//            this.mLoadText.setText("正在缓冲...");
//            this.cancelDismissTopBottomTimer();
                break;
            case 7:
                mNiceVideoPlayer.restart();
//                this.cancelUpdateProgressTimer();
//            this.setTopBottomVisible(false);
//            this.mImage.setVisibility(0);
//            this.mCompleted.setVisibility(0);
        }
    }

    @Override
    protected void onPlayModeChanged(int i) {

    }

    @Override
    protected void reset() {

    }

    @Override
    protected void updateProgress() {

    }

    @Override
    protected void showChangePosition(long l, int i) {

    }

    @Override
    protected void hideChangePosition() {

    }

    @Override
    protected void showChangeVolume(int i) {

    }

    @Override
    protected void hideChangeVolume() {

    }

    @Override
    protected void showChangeBrightness(int i) {

    }

    @Override
    protected void hideChangeBrightness() {

    }
}
